<?php

$returnString="";
$i=0;
$directory = "/Applications/MAMP/htdocs/HolidayParty/GIFs/";
$images = glob($directory . "*.gif");
usort($images,"sort_by_mtime");


//print each file name
foreach($images as $image){
 if(filesize($image)>512000){
	 uploadDropbox($image);
	 $returnString.=createPost($i,$image);
	 $i++;
 }
}

echo $returnString."";



function uploadDropbox($img){
	if(!file_exists("/Users/dboardman/Dropbox/Public/tumblr/upload/".basename($img))){
		copy($img, "/Users/dboardman/Dropbox/Public/tumblr/upload/".basename($img));
		}
}
 
function createPost($i,$image){
	$html="";
	//if($i<15){
		//echo filesize($image)."<br/>";
		 if($i==0) $html='<div class="bottomGIF"><img src="GIFs/'.basename($image).'" alt=""/></div>';
		 else $html='<div class="bottomGIF"><img src="GIFs/'.basename($image).'" alt=""/></div>';
	 //}
	 return $html;
} 
 
function sort_by_mtime($file1,$file2) {
    $time1 = filemtime($file1);
    $time2 = filemtime($file2);
    if ($time1 == $time2) {
        return 0;
    }
    return ($time1 < $time2) ? 1 : -1;
 }
	

?>